package com.xiao.common.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @Author xiaoxiaoping
 * @Date 2020/3/9 13:50
 * @Version 1.0
 */
@Data
public abstract class BaseEntity implements Serializable {
    /**
     *
     * 创建人id
     *
     * @mbggenerated
     */
    private String createrId;

    /**
     *
     * 创建人姓名
     *
     * @mbggenerated
     */
    private String createrName;

    /**
     *
     * 创建时间
     *
     * @mbggenerated
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    /**
     *
     * 修改人id
     *
     * @mbggenerated
     */
    private String updaterId;

    /**
     *
     * 修改人姓名
     *
     * @mbggenerated
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private String updaterName;

    /**
     *
     * 修改时间
     *
     * @mbggenerated
     */
    private Date updateTime;

    public void setCreateUser(DictEmployee dictEmployee) {
        this.createTime = new Date();
        if (null != dictEmployee) {
            this.createrId =  StringUtils.isEmpty(dictEmployee.getEMPID())?"1":dictEmployee.getEMPID();
            this.createrName = dictEmployee.getEMPNAME();
        }
    }



    /**
     * 设置修改人ID,修改人姓名,修改时间(当前)
     *
     * @param dictEmployee
     */
    public void setUpdaterUser(DictEmployee dictEmployee) {
        this.updateTime = new Date();
        if (null != dictEmployee) {
            this.updaterId = StringUtils.isEmpty(dictEmployee.getEMPID())?"1":dictEmployee.getEMPID();
            this.updaterName = dictEmployee.getEMPNAME();
        }
    }
}
